﻿<%@ WebHandler Language="C#" Class="uploadify" %>

using System;
using System.Web;
using System.IO;

public class uploadify : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;

        try
        {

            HttpPostedFile postedFile = context.Request.Files["Filedata"];



            string savepath = "";

            string tempPath = "";

            tempPath = context.Server.UrlDecode(context.Request.Form["folder"]);

            savepath = context.Server.MapPath("~/"+tempPath);

            string filename = postedFile.FileName;

            if (!Directory.Exists(savepath))
                Directory.CreateDirectory(savepath);



            postedFile.SaveAs(savepath + @"\" + filename);

            context.Response.Write(tempPath + "/" + filename);

            context.Response.StatusCode = 200;

        }

        catch (Exception ex)
        {

            context.Response.Write("Error: " + ex.Message);

        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}